VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsStock"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Dim vSQL As String

Public pNumError As Long
Public pDesError As String
Public pCanReg As Long
Public pRS As ADODB.Recordset
Public pIdDevuelto As Long

Private vIdmovimiento As Long

Public Property Let Idmovimiento(ByVal VData As Long)
    vIdmovimiento = VData
End Property
Public Property Get Idmovimiento() As Long
    Idmovimiento = vIdmovimiento
End Property

Private Sub AsignarValores(Optional ByVal rs As ADODB.Recordset, Optional pNoAsigRs As Boolean)
    If Not pNoAsigRs Then
        Set Me.pRS = rs
    End If
    Me.pCanReg = objCnxAeros.pCanReg
    Me.pDesError = objCnxAeros.pDesError
    Me.pIdDevuelto = objCnxAeros.pUltIdenOtor
    Me.pNumError = objCnxAeros.pNumError
End Sub


Public Function insertar_movimiento(ByVal id_articulo As Long, _
                                    ByVal Cantidad As Long, _
                                    ByVal tipo_movimiento As Boolean) As Boolean
Dim vSQL As String
Dim tmov As Integer

    tmov = 0
    If tipo_movimiento Then tmov = 1
    
    vSQL = " INSERT INTO movimientos (id_articulo, Cantidad, tipo_mov, fecha) " & _
           " VALUES (" & id_articulo & "," & Cantidad & "," & tmov & ",'" & Date & "')"
    If objCnxAeros.EjecutarComando(vSQL) Then
        insertar_movimiento = True
    Else
        insertar_movimiento = False
    End If
    AsignarValores , True
 
End Function

Public Sub sel_movimientos(ByVal desde_date1 As Date, ByVal hasta_date2 As Date)
Dim strSQL As String
Dim rs As New ADODB.Recordset

    strSQL = " SELECT movimientos.id_movimiento, " & _
             "       (lineas.linea & ' ' & articulos.articulo) AS Articulo, " & _
             "       iif(movimientos.tipo_mov = true , movimientos.cantidad, -movimientos.cantidad) AS  Movimiento , " & _
             "       articulos.Cantidad as [Stock Actual]" & _
             " From movimientos " & _
             " INNER JOIN (articulos  INNER JOIN lineas ON articulos.id_linea = lineas.Id_linea) " & _
             "     ON movimientos.id_articulo = articulos.id_articulo " & _
             "   WHERE movimientos.fecha  between '" & desde_date1 & "' And '" & hasta_date2 & "'"
             
                
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs

End Sub
